package com.lyp.lease.web.admin.test;

import com.lyp.lease.common.context.LoginUser;
import com.lyp.lease.common.utils.JwtUtil;
import com.lyp.lease.model.enums.ItemType;
import com.lyp.lease.web.admin.mapper.GraphInfoMapper;
import com.lyp.lease.web.admin.mapper.LabelInfoMapper;
import com.lyp.lease.web.admin.service.GraphInfoService;
import com.lyp.lease.web.admin.vo.graph.GraphVo;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.List;

@SpringBootTest
public class test01 {

    @Autowired
    GraphInfoService graphInfoService;
    @Autowired
    GraphInfoMapper graphInfoMapper;
    @Autowired
    LabelInfoMapper labelInfoMapper;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Test
    public void test1(){
        // 测试1
        ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
        stringStringValueOperations.set("zhangsan","666");

        String s = stringStringValueOperations.get("zhangsan");
        System.out.println(s);

    }

    String secretKey = "lvp1111110000000000000000000000000000000000000000000000";
    String ip = "127.0.0.1";
    String username = "zhangsan";
    String salt = secretKey+ip;

    String token = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJ1c2VyaWQiOjEsInVzZXJuYW1lIjoiemhhbmdzYW4ifQ.FbCMZiBZlUla7NgJXHdCQRg0xkzf-f_xFt2-wszw_ZEeqTR6PxW5E3MYw0cCco43wEbHrNMFjROva-sFQT-30w";

    @Test
    public void parse(){
        Jws<Claims> claimsJws = Jwts.parserBuilder().setSigningKey(Keys.hmacShaKeyFor(salt.getBytes()))
                .build()
                .parseClaimsJws(token);
        System.out.println(claimsJws);
    }

    @Test
    public void testJwt(){




        LoginUser loginUser = new LoginUser();
        loginUser.setUserid(1L);
        loginUser.setUsername("zhangsan");


        String token = Jwts
                .builder()
                .setHeaderParam("type","JWT")
                .setHeaderParam("alg","HS256")
                .claim("userid",loginUser.getUserid())
                .claim("username",loginUser.getUsername())
                .signWith(Keys.hmacShaKeyFor(salt.getBytes()))
                .compact();
        System.out.println(token);
    }





}
